from datetime import datetime
from typing import Literal, Optional

from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel

from module_admin.annotation.pydantic_annotation import as_query, as_form


class ContrastLogModel(BaseModel):
    """
    对比日志表对应pydantic模型
    """

    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='对比日志主键')
    source_file_name: Optional[str] = Field(default=None, description='原文件名称')
    source_file_path: Optional[str] = Field(default=None, description='原文件地址')
    target_file_name: Optional[str] = Field(default=None, description='目标文件名称')
    target_file_path: Optional[str] = Field(default=None, description='目标文件地址')
    operator: Optional[str] = Field(default=None, description='操作人员')
    host_ip: Optional[str] = Field(default=None, description='主机地址')
    operating_location: Optional[str] = Field(default=None, description='操作地点')
    request_param: Optional[str] = Field(default=None, description='请求参数')
    operation_time: Optional[datetime] = Field(default=None, description='操作时间')


class ContrastLogQueryModel(ContrastLogModel):
    """
    对比日志管理不分页查询模型
    """

    order_by_column: Optional[str] = Field(default=None, description='排序的字段名称')
    is_asc: Optional[Literal['ascending', 'descending']] = Field(
        default=None, description='排序方式（ascending升序 descending降序）'
    )
    begin_time: Optional[str] = Field(default=None, description='开始时间')
    end_time: Optional[str] = Field(default=None, description='结束时间')


@as_query
@as_form
class ContrastLogPageQueryModel(ContrastLogQueryModel):
    """
    对比日志管理分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeleteContrastLogModel(BaseModel):
    """
    删除操作日志模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    ids: str = Field(description='需要删除的日志主键')
